﻿using System.ComponentModel.DataAnnotations;

namespace RemoteSensingImageDirectServer.Models.Request.Validation
{
    public class EnumValueAttribute : ValidationAttribute
    {
        private readonly string[] _attrs;

        public EnumValueAttribute(params string[] attrs)
        {
            this._attrs = attrs;
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value is string str)
            {
                if (_attrs.Contains(str.ToLower()))
                    return ValidationResult.Success;
                else
                    return new ValidationResult(base.ErrorMessage);
            }
            return new ValidationResult(base.ErrorMessage);
        }
    }
}
